# $Id: makefile.in,v 1.56 2007/04/08 21:10:55 tom Exp $
# template makefile for VIALOG
#
SHELL		= /bin/sh

srcdir		= .


prefix		= /usr/local
exec_prefix	= ${prefix}

top_builddir	= .

x		= 
o		= .o
a		= .a

DESTDIR		=

bindir		= ${exec_prefix}/bin
includedir	= ${prefix}/include
libdir		= ${exec_prefix}/lib
mandir		= ${prefix}/man

BINDIR		= $(DESTDIR)$(bindir)
INCLUDEDIR	= $(DESTDIR)$(includedir)
LIBDIR		= $(DESTDIR)$(libdir)
MANDIR		= $(DESTDIR)$(mandir)

MAN1DIR		= $(MANDIR)/man1
MAN3DIR		= $(MANDIR)/man3

# see po/makefile
localedir       = $(prefix)/share/locale

CFLAGS		= -g -O2
CPPFLAGS	=  -D_GNU_SOURCE -DHAVE_CONFIG_H -I. -I$(srcdir) -DLOCALEDIR=\"$(localedir)\"
EXTRA_CFLAGS	= 
CC		= gcc
AR		= ar
LDFLAGS		= 
LIBS		= -lpthread -lncurses  -lm -L/lib # 
RANLIB		= ranlib

RM		= rm -f
LINT		= lint

LIBTOOL		=  
LIBTOOL_OPTS	= 
LIBTOOL_CLEAN	= 
LIBTOOL_COMPILE	= 
LIBTOOL_CREATE	= ${AR} -cr
LIBTOOL_LINK	= ${CC}
LIBTOOL_INSTALL	= 
LIBTOOL_UNINSTALL = 

INSTALL		= /usr/bin/install -c
INSTALL_PROGRAM	= $(LIBTOOL_INSTALL) ${INSTALL}
INSTALL_SCRIPT	= ${INSTALL}
INSTALL_DATA	= ${INSTALL} -m 644

LINK		= $(LIBTOOL_LINK)

PACKAGE		= `echo vialog |sed s,x,x,`

DLG_TTS   = ESPEAK

ifeq ($(DLG_TTS), FLITE)
FL_LANG  = 
FL_VOX   = 
FL_LEX   = 

flite_dir:=
flite_include_dir:=
FLITE_LIBS:=$(flite_dir)/lib/libflite_$(FL_VOX).a $(flite_dir)/lib/libflite_$(FL_LEX).a $(flite_dir)/lib/libflite_$(FL_LANG).a $(flite_dir)/lib/libflite.a
EXTRA_CPPFLAGS	=  -I$(flite_include_dir)
else ifeq ($(DLG_TTS), ESPEAK)
espeak_dir:=/usr/lib
espeak_include_dir:=/usr/local/espeak-1.23-source/src
#ESPEAK_LIBS:=$(espeak_dir)/libespeak.a
ESPEAK_LIBS:=-lespeak -L$(espeak_dir)
EXTRA_CPPFLAGS	=  -I$(espeak_include_dir)
endif

#
# Standard .c to .o compile line.
#
.SUFFIXES: .c $o
.c$o :
# compiling
	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CPPFLAGS) $(EXTRA_CPPFLAGS) -c $<

EXTRAOBJS =  trace$o rc$o calendar$o fselect$o timebox$o formbox$o guage$o pause$o progressbox$o tailbox$o mixedform$o mixedgauge$o
OBJECTS = $(EXTRAOBJS) \
	arrows$o \
	buttons$o \
	checklist$o \
	dlg_keys$o \
	editbox$o \
	inputbox$o \
	inputstr$o \
	menubox$o \
	mouse$o \
	mousewget$o \
	msgbox$o \
	textbox$o \
	ui_getc$o \
	util$o \
	version$o \
	voice$o \
	yesno$o

LIB_OBJECT = ${OBJECTS}

SRCS = $(OBJECTS:$o=.c)
HDRS = \
	vialog.h \
	dlg_colors.h \
	dlg_config.h \
	dlg_keys.h

LIB	= libvialog$a
PROG	= vialog$x
ALL	= $(LIB) $(PROG)

BIN_DIRS	= $(BINDIR) $(MAN1DIR)
LIB_DIRS	= $(LIBDIR) $(INCLUDEDIR)

all	:: $(ALL)

#install	:: install-lib
#uninstall	:: uninstall-lib

# :
#	@echo "Building GNU gettext library..."
#	@cd intl && $(MAKE) 

vialog$o \
$(OBJECTS) : $(srcdir)/vialog.h $(srcdir)/dlg_keys.h dlg_config.h VERSION

$(LIB) : $(LIB_OBJECT)
	$(LIBTOOL_CREATE) $(LIB) $(LIB_OBJECT)
	$(RANLIB) $@

vialog$x : $(LIB) vialog$o # 
	$(LINK) -o $@ vialog$o -L. -lvialog $(LDFLAGS) $(LIBS) $(FLITE_LIBS) $(ESPEAK_LIBS)

clean	\
distclean \
install \
install-full \
install-strip \
uninstall ::
	@echo making $@
#	@-test -f intl/makefile && cd intl && $(MAKE)  $@
#	@-test -f po/makefile && cd po && $(MAKE)  $@

clean	::
	@- $(RM) -r autom4te.cache
	- $(RM) *.*cov *.da *.bb *.bbg
	- $(LIBTOOL_CLEAN) $(RM) *$o $(ALL)
	- $(RM) headers.sed
	- $(RM) core *~ tags TAGS

distclean :: clean
	$(RM) intl/libintl.h intl/po2tbl.sed
	$(RM) makefile dlg_config.h config.cache config.log config.status
	$(RM) samples/install/makefile
	$(RM) vialog-config

install :: install-bin install-man
	@echo "made $@"

install-full :: install-lib install-bin install-man
	@echo "made $@"

install-strip :: $(PROG) $(BINDIR)
	$(INSTALL_PROGRAM) -s $(PROG) $(BINDIR)

uninstall :: uninstall-bin uninstall-man
	@echo "made $@"

uninstall-full :: uninstall-bin uninstall-man uninstall-lib
	@echo "made $@"

install-bin : $(PROG) $(BINDIR) 
	$(INSTALL_PROGRAM) $(PROG) $(BINDIR)/$(PACKAGE)$x

uninstall-bin :
	$(RM) $(BINDIR)/$(PACKAGE)$x

install-man :: $(MAN1DIR)
	$(INSTALL_DATA) $(srcdir)/vialog.1 $(MAN1DIR)/$(PACKAGE).1

uninstall-man ::
	$(RM) $(MAN1DIR)/$(PACKAGE).1

# most users do not want/need the library, so the install rules are distinct.
install-lib :: $(BINDIR) vialog-config
	@ echo "** installing config script in $(BINDIR)"
	@ $(INSTALL_SCRIPT) vialog-config $(BINDIR)

install-lib :: $(LIB_DIRS) $(LIB) headers.sed
	@ echo "** installing library in $(LIBDIR)"
	@ $(LIBTOOL_INSTALL) $(INSTALL_DATA) $(LIB) $(LIBDIR)
	@ echo "** installing headers in $(INCLUDEDIR)"
	@ $(SHELL) $(srcdir)/headers.sh $(INSTALL_DATA) $(INCLUDEDIR) $(srcdir) vialog.h
	@ $(SHELL) $(srcdir)/headers.sh $(INSTALL_DATA) $(INCLUDEDIR) $(srcdir) dlg_colors.h
	@ $(SHELL) $(srcdir)/headers.sh $(INSTALL_DATA) $(INCLUDEDIR) $(srcdir) dlg_keys.h
	@ $(SHELL) $(srcdir)/headers.sh $(INSTALL_DATA) $(INCLUDEDIR) .         dlg_config.h

uninstall-lib :: $(BINDIR)
	$(RM) $(BINDIR)/vialog-config

uninstall-lib :: $(LIB_DIRS)
	- $(LIBTOOL_UNINSTALL) $(RM) $(LIBDIR)/$(LIB)
	$(RM) $(INCLUDEDIR)/vialog.h
	$(RM) $(INCLUDEDIR)/dlg_colors.h
	$(RM) $(INCLUDEDIR)/dlg_keys.h
	$(RM) $(INCLUDEDIR)/dlg_config.h

install-lib :: $(MAN3DIR)
	$(INSTALL_DATA) $(srcdir)/vialog.3 $(MAN3DIR)/$(PACKAGE).3

uninstall-lib ::
	$(RM) $(MAN3DIR)/$(PACKAGE).3

headers.sed : $(srcdir)/headers.sh
	$(SHELL) $(srcdir)/headers.sh $(INCLUDEDIR) $(srcdir)

ifeq ($(DLG_TTS), FLITE)
voice.o: voice.c
	$(CC) $(CFLAGS) -I. -I$(flite_include_dir) -DREGISTER_VOX=register_$(subst cmu_us_kal16,cmu_us_kal,$(FL_VOX)) -c -o $@ $<
else ifeq ($(DLG_TTS), ESPEAK)
voice.o: voice.c
	$(CC) $(CFLAGS) -I. -I$(espeak_include_dir) -c -o $@ $<
endif

$(MAN1DIR) \
$(MAN3DIR) \
$(BINDIR) \
$(INCLUDEDIR) \
$(LIBDIR) : ; $(srcdir)/mkdirs.sh $@

tags :
	ctags $(SRCS) $(HDRS)

TAGS :
	etags $(SRCS) $(HDRS)

lint:
	$(LINT) $(CPPFLAGS) *.c
